
//=======================================
// FIGURE 1
//=======================================

local bc_threshold=100	
set scheme tufte
local us_color="blue"
local jp_color="orange_red"

global DATA  "path/to/input/data"   
global OUT "path/to/output/folder"
global INT "path/to/intermediate/files"

// Visual inspection of parallel trends (JP-US pairs applicant cites)

use "$DATA\twincites_applicant_did_prep.dta", clear
drop if backcite_count_citing>`bc_threshold'
sort family_cited priority_citing_d
duplicates drop family_cited nonJP, force
duplicates tag family_cited, gen(tag)
drop if tag==0
drop tag
local policy_date=14943
local window_size=7
local window_num=26
gen time=floor((US_filing_date_d_cited-`policy_date')/`window_size') + 0.5
gen count=1
collapse (mean) lag (sum) count, by(nonJP time)

sum lag if nonJP==1 & time<0 [fweight=count]
gen US_mean=r(mean) if time<0
sum lag if nonJP==1 & time>=0 [fweight=count]
replace US_mean=r(mean) if time>=0
sum lag if nonJP==0 & time<0 [fweight=count]
gen JP_mean=r(mean) if time<0
sum lag if nonJP==0 & time>=0 [fweight=count]
replace JP_mean=r(mean) if time>=0

sort time nonJP
tw (sc lag time if nonJP==1 , color(`us_color') m(diamond_hollow) leg(lab(1 US inventors))) (sc lag time if nonJP==0, color(`jp_color') m(circle) leg(lab(2 JP inventors))) (line US_mean time, color(`us_color') lp(dash) leg(lab(3 US mean))) (line JP_mean time, color(`jp_color') lp(dash) leg(lab(4 JP mean))),  xline(0, lwidth(thin) lcolor(gray)) yti(log(lag)) xti(US application date (weeks relative to AIPA implementation)) xlabel(-26 0 26) ylabel(6 6.5 7) leg(cols(2))
save "$OUT\twincites_applicant_graph.dta", replace

graph export "$OUT\parallel_trend_applicant.pdf", as(pdf) name("Graph") replace













